function c(){
    var list;
    list=new XMLHttpRequest();
    list.onreadystatechange=function(){

        if (list.readyState==4 && list.status==200){
            document.querySelector("#list").innerHTML='';
            var json = JSON.parse(list.responseText);
            console.log(json.data);
            for(var i = 0;i<json.data.length;i++){
                var tr = document.createElement('tr');
                var name = document.createElement('td');
                var sex = document.createElement('td');
                var age = document.createElement('td');
                name.innerHTML = json.data[i].studentName;
                sex.innerHTML = json.data[i].sex;
                age.innerHTML = json.data[i].age;
                tr.appendChild(name);
                tr.appendChild(sex);
                tr.appendChild(age);

                document.querySelector("#list").appendChild(tr);
            }
        }
    };

    list.open("GET","http://localhost/ajaxApi/public/index.php/index/student/student",true);
    list.send();

}
c();

document.querySelector("#btn").addEventListener('click',function(){
    var n = document.querySelector("#n").value;
    console.log(n);
    var s = document.querySelector("#s").value;
    console.log(s);
    var a = document.querySelector("#a").value;
    console.log(a);


//    ajax代码
    var xmlhttp;
    if (window.XMLHttpRequest){
        //  IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
        xmlhttp=new XMLHttpRequest();
    }else{
        // IE6, IE5 浏览器执行代码
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function(){
        if (xmlhttp.readyState==4 && xmlhttp.status==200){

            console.log(xmlhttp.responseText);
            c();

        }

    };
    xmlhttp.open("GET","http://localhost/ajaxApi/public/index.php/index/student/addStudent?studentName="+n+"&sex="+s+"&age="+a,true);
    xmlhttp.send();

});


